﻿using System.Data;

using System.Web.UI;
using System.Web.UI.WebControls;





namespace XunPan.Web.Controls
{

    /// <summary>
    /// webbox for warecube
    /// 加载最新发布的warecube链接
    /// 
    /// </summary>
    /// <remarks></remarks>
    public class WebBoxWareCube : WebControl, INamingContainer
    {
        //ToDo: Add Implements Clauses for implementation methods of these interface(s)


        private DataTable _warecubesTable;
        private string _loadingText;
        private string _loadingImage;
        private int _columns = 1;

        private int _itemspercell = 5;

        private string _datafieldformat;

        private WebBoxType _type = WebBoxType.Latest;
        //*********************************************************************
        //
        //
        // Creates a WebControl with a table tag as its containing
        // tag.
        //
        //*********************************************************************

        public WebBoxWareCube()
            : base(HtmlTextWriterTag.Table)
        {
            Visible = false;


            if ((Context != null))
            {
                // Get data objects


                switch (_type)
                {
                    case WebBoxType.Latest:
                        break;
                    //delete by jiang 20120521
                    //_warecubesTable = LayerUtility.GetAllWareCubes

                }


                Visible = true;

            }
        }
        //New 

        public WebBoxType Type
        {
            get { return _type; }
            set { _type = value; }
        }
        public string LoadingImage
        {
            get { return _loadingImage; }
            set { _loadingImage = value; }
        }



        public int Columns
        {
            get { return _columns; }
            set { _columns = value; }
        }
        public int ItemsPerCell
        {
            get { return _itemspercell; }
            set { _itemspercell = value; }
        }

        public string LoadingText
        {
            get { return _loadingText; }
            set { _loadingText = value; }
        }

        public string DataFieldFormat
        {
            get { return _datafieldformat; }
            set { _datafieldformat = value; }
        }
        //*********************************************************************
        //
        // WareCubeID Property
        //
        // The WareCubeID of the control bond to from query string in context
        //
        //*********************************************************************


        public DataTable WareCubeTable
        {

            get { return _warecubesTable; }
        }

        //*********************************************************************
        //
        // CreateChildControls Method
        //
        // Adds controls to this control's Controls collection.
        //
        //*********************************************************************

        protected override void CreateChildControls()
        {

        }
        //CreateChildControls



        //*********************************************************************
        //
        // Render Method
        //
        // Renders different moderation options.
        //
        //*********************************************************************
        protected override void Render(HtmlTextWriter tw)
        {
            base.Render(tw);

        }
        //Render

        //*********************************************************************
        //
        // RenderContents Method
        //
        // Render the two dropdownlists.
        //
        //*******************************************************************

        protected override void RenderContents(HtmlTextWriter tw)
        {



            if (_warecubesTable != null)
            {

                int itemcount = _warecubesTable.Rows.Count;



                for (int i = 1; i <= itemcount; i++)
                {
                    if ((i % (_columns * _itemspercell)) == 1)
                    {
                        //open tr
                        tw.RenderBeginTag(HtmlTextWriterTag.Tr);

                    }
                    if (i % _itemspercell == 1)
                    {
                        //open td
                        tw.RenderBeginTag(HtmlTextWriterTag.Td);
                        //render ul list control
                        tw.RenderBeginTag(HtmlTextWriterTag.Ul);
                    }
                    //render li
                    tw.RenderBeginTag(HtmlTextWriterTag.Li);
                    //render a
                    tw.AddAttribute("href", string.Format(_datafieldformat, _warecubesTable.Rows[i - 1]["wareCubeID"]));
                    tw.RenderBeginTag(HtmlTextWriterTag.A);
                    tw.Write(_warecubesTable.Rows[i - 1]["displayName"].ToString());
                    // close a link
                    tw.RenderEndTag();
                    // close li
                    tw.RenderEndTag();

                    if (i % _itemspercell == 0)
                    {
                        // close ul
                        tw.RenderEndTag();
                        // close td
                        tw.RenderEndTag();
                    }
                    if ((i % (_columns * _itemspercell)) == 0)
                    {
                        //close tr
                        tw.RenderEndTag();
                    }

                }



            }


        }
        //RenderContents

        public enum WebBoxType : int
        {
            UnDefined = 0,
            Latest = 1,
            TopTen = 2

        }
    }
    //ModerationAction 




}
